﻿
namespace NetROS.Tiers.Windows.Forms
{
	/// <summary>
	/// abstract GrupaDozvole typed datagridview
	/// </summary>
	[System.ComponentModel.DesignerCategoryAttribute("code")]
	public abstract class GrupaDozvoleDataGridViewBase : System.Windows.Forms.UserControl
	{	
		/// <summary> 
		/// Thrown when the current Entity changed.
		/// </summary>
		public event System.EventHandler<GrupaDozvoleDataGridViewEventArgs> CurrentEntityChanged;
		
		#region Fields
				
		/// <summary> 
		/// the current entity.
		/// </summary>
		private Entities.GrupaDozvole _currentGrupaDozvole = null;
		//private Dictionary<string, string> _columnsHeaders = new Dictionary<string, string>();
		
		/// <summary> 
		/// the datagridview instance
		/// </summary>
		protected System.Windows.Forms.DataGridView uxGrupaDozvoleDataGridView;
		
		/// <summary> 
		/// the errorprovider
		/// </summary>
		protected System.Windows.Forms.ErrorProvider uxGrupaDozvoleErrorProvider;
		
		/// <summary> 
		/// the bindingsource
		/// </summary>
		protected System.Windows.Forms.BindingSource uxGrupaDozvoleBindingSource;
		
		/// <summary> 
		/// the DGV column associated with the IDGrupaDjelatnik property
		/// </summary>
		protected System.Windows.Forms.DataGridViewComboBoxColumn uxIDGrupaDjelatnikDataGridViewColumn;
		
		/// <summary> 
		/// the DGV column associated with the OrgJed property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxOrgJedDataGridViewColumn;
		
		/// <summary> 
		/// the DGV column associated with the DozvolaZapisa property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxDozvolaZapisaDataGridViewColumn;
		
		/// <summary> 
		/// the DGV column associated with the DozvolaPregled property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxDozvolaPregledDataGridViewColumn;
		
		/// <summary> 
		/// the DGV column associated with the ID property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxIDDataGridViewColumn;
		
		#endregion
					
		#region Combo list
		
				
		private Entities.TList<Entities.GrupaDjelatnik> _IDGrupaDjelatnikList;
		
		/// <summary> 
		/// The list of selectable GrupaDjelatnik
		/// </summary>
		[System.ComponentModel.Category("DropDownList BindingSources")]
		public Entities.TList<Entities.GrupaDjelatnik> IDGrupaDjelatnikList
		{
			get {return this._IDGrupaDjelatnikList;}
			set 
			{
				this._IDGrupaDjelatnikList = value;
				this.uxIDGrupaDjelatnikDataGridViewColumn.DataSource = null;
				this.uxIDGrupaDjelatnikDataGridViewColumn.DataSource = this._IDGrupaDjelatnikList;
			}
		}
		
		private bool _allowNewItemInIDGrupaDjelatnikList;
		
		/// <summary> 
		/// Indicates if user can add an item in the list of GrupaDjelatnik
		/// </summary>
		[System.ComponentModel.Category(".netTiers"), System.ComponentModel.Description("Indicates if end user can add a new item in the combobox. an event will be thrown then.")]
		public bool AllowNewItemInIDGrupaDjelatnikList
		{
			get { return _allowNewItemInIDGrupaDjelatnikList;}
			set
			{
				this._allowNewItemInIDGrupaDjelatnikList = value;
				this.uxIDGrupaDjelatnikDataGridViewColumn.DisplayStyle = value ? System.Windows.Forms.DataGridViewComboBoxDisplayStyle.ComboBox : System.Windows.Forms.DataGridViewComboBoxDisplayStyle.DropDownButton;
			}
		}
		
		#endregion
		
		#region Main Datasource
		
		private Entities.TList<Entities.GrupaDozvole> _GrupaDozvoleList;
				
		/// <summary> 
		/// The list of GrupaDozvole to be displayed in the DGV.
		/// </summary>
		[System.ComponentModel.Category("Data")]
		public Entities.TList<Entities.GrupaDozvole> GrupaDozvoleList
		{
			get {return this._GrupaDozvoleList;}
			set
			{
				this._GrupaDozvoleList = value;
				this.uxGrupaDozvoleBindingSource.DataSource = null;
				this.uxGrupaDozvoleBindingSource.DataSource = value;
				this.uxGrupaDozvoleDataGridView.DataSource = null;
				this.uxGrupaDozvoleDataGridView.DataSource = this.uxGrupaDozvoleBindingSource;				
				//this.uxGrupaDozvoleBindingSource.ListChanged += new System.ComponentModel.ListChangedEventHandler(uxGrupaDozvoleBindingSource_ListChanged);
				this.uxGrupaDozvoleBindingSource.CurrentItemChanged += new System.EventHandler(OnGrupaDozvoleBindingSourceCurrentItemChanged);
			}
		}
		
		private void OnGrupaDozvoleBindingSourceCurrentItemChanged(object sender, System.EventArgs e)
		{
			_currentGrupaDozvole = uxGrupaDozvoleBindingSource.Current as Entities.GrupaDozvole;
			
			if (_currentGrupaDozvole != null)
			{
				_currentGrupaDozvole.Validate();
			}
			//_GrupaDozvole.Validate();
			OnCurrentEntityChanged();
		}

		//void uxGrupaDozvoleBindingSource_ListChanged(object sender, System.ComponentModel.ListChangedEventArgs e)
		//{
			//throw new Exception("The method or operation is not implemented.");
		//}		
		
		#endregion
		
		/// <summary>
		/// Gets the currently selected <c cref="Entities.GrupaDozvole"/> instance.
		/// </summary>
		public Entities.GrupaDozvole SelectedGrupaDozvole
		{
			get {return this._currentGrupaDozvole;}
		}
		
		#region other properties
		
		/// <summary>
		/// Gets or sets a value indicating whether you have provided your own data-management operations for the DataGridView control.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public bool VirtualMode
		{
			get {return this.uxGrupaDozvoleDataGridView.VirtualMode;}
			set
			{
				this.uxGrupaDozvoleDataGridView.VirtualMode = value;
			}
		}
		
		/// <summary>
		/// Gets or sets a value indicating whether the option to add rows is displayed to the user.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public bool AllowUserToAddRows
		{
			get {return this.uxGrupaDozvoleDataGridView.AllowUserToAddRows;}
			set {this.uxGrupaDozvoleDataGridView.AllowUserToAddRows = value;}
		}
		
		/// <summary>
		/// Gets or sets a value indicating whether the user is allowed to delete rows from the DataGridView.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public bool AllowUserToDeleteRows
		{
			get {return this.uxGrupaDozvoleDataGridView.AllowUserToDeleteRows;}
			set {this.uxGrupaDozvoleDataGridView.AllowUserToDeleteRows = value;}
		}
		
		/// <summary>
		/// Gets the <c cref="DataGridView"/> instance.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public System.Windows.Forms.DataGridView DataGridView
		{
			get {return this.uxGrupaDozvoleDataGridView;}
		}
		
		/// <summary>
		/// Gets a collection that contains all the columns in the control.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]		
		[System.ComponentModel.DesignerSerializationVisibilityAttribute(System.ComponentModel.DesignerSerializationVisibility.Visible)]
		//[System.ComponentModel.EditorAttribute("System.Windows.Forms.Design.DataGridViewColumnCollectionEditor, System.Design", typeof(System.Drawing.Design.UITypeEditor))] 
		public System.Windows.Forms.DataGridViewColumnCollection Columns
		{
			get { return this.uxGrupaDozvoleDataGridView.Columns; }
		}
		
		#endregion
		
		/// <summary> 
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.IContainer components = null;
	
		/// <summary> 
		/// Clean up any resources being used.
		/// </summary>
		/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
		protected override void Dispose(bool disposing)
		{
			if (disposing && (components != null))
			{
				components.Dispose();
			}
			base.Dispose(disposing);
		}
	
		#region Constructor
	
		/// <summary>
		/// Initializes a new instance of the <see cref="GrupaDozvoleDataGridViewBase"/> class.
		/// </summary>
		public GrupaDozvoleDataGridViewBase()
		{			
			this.components = new System.ComponentModel.Container();			
			
			this.uxGrupaDozvoleDataGridView = new System.Windows.Forms.DataGridView();
			this.uxGrupaDozvoleBindingSource = new System.Windows.Forms.BindingSource(this.components);
			this.uxGrupaDozvoleErrorProvider = new System.Windows.Forms.ErrorProvider(this.components);
			this.uxIDGrupaDjelatnikDataGridViewColumn = new System.Windows.Forms.DataGridViewComboBoxColumn();
			this.uxOrgJedDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.uxDozvolaZapisaDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.uxDozvolaPregledDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.uxIDDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			//this.uxIDGrupaDjelatnikBindingSource = new GrupaDjelatnikBindingSource(this.components);
			//((System.ComponentModel.ISupportInitialize)(this.uxIDGrupaDjelatnikBindingSource)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.uxGrupaDozvoleDataGridView)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.uxGrupaDozvoleBindingSource)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.uxGrupaDozvoleErrorProvider)).BeginInit();
			this.SuspendLayout();
						
			// 
			// uxGrupaDozvoleErrorProvider
			// 
			this.uxGrupaDozvoleErrorProvider.ContainerControl = this;
			this.uxGrupaDozvoleErrorProvider.DataSource = this.uxGrupaDozvoleBindingSource;						
			// 
			// uxGrupaDozvoleDataGridView
			// 
			this.uxGrupaDozvoleDataGridView.AutoGenerateColumns = false;
			this.uxGrupaDozvoleDataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
			this.uxGrupaDozvoleDataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
		this.uxIDGrupaDjelatnikDataGridViewColumn,
		this.uxOrgJedDataGridViewColumn,
		this.uxDozvolaZapisaDataGridViewColumn,
		this.uxDozvolaPregledDataGridViewColumn,
		this.uxIDDataGridViewColumn			});
			this.uxGrupaDozvoleDataGridView.Dock = System.Windows.Forms.DockStyle.Fill;
			this.uxGrupaDozvoleDataGridView.Location = new System.Drawing.Point(0, 0);
			this.uxGrupaDozvoleDataGridView.Name = "uxGrupaDozvoleDataGridView";
			this.uxGrupaDozvoleDataGridView.Size = new System.Drawing.Size(470, 300);
			this.uxGrupaDozvoleDataGridView.TabIndex = 0;	
			this.uxGrupaDozvoleDataGridView.BackgroundColor = System.Drawing.Color.WhiteSmoke;
			this.uxGrupaDozvoleDataGridView.EnableHeadersVisualStyles = false;
			this.uxGrupaDozvoleDataGridView.DataError += new System.Windows.Forms.DataGridViewDataErrorEventHandler(this.OnGrupaDozvoleDataGridViewDataError);
			this.uxGrupaDozvoleDataGridView.CellValueNeeded += new System.Windows.Forms.DataGridViewCellValueEventHandler(this.OnGrupaDozvoleDataGridViewCellValueNeeded);
			this.uxGrupaDozvoleDataGridView.CellValuePushed += new System.Windows.Forms.DataGridViewCellValueEventHandler(this.OnGrupaDozvoleDataGridViewCellValuePushed);
			
			//
			// uxIDGrupaDjelatnikDataGridViewColumn
			//
			this.uxIDGrupaDjelatnikDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxIDGrupaDjelatnikDataGridViewColumn.DataPropertyName = "IDGrupaDjelatnik";
			this.uxIDGrupaDjelatnikDataGridViewColumn.HeaderText = "IDGrupaDjelatnik";
			this.uxIDGrupaDjelatnikDataGridViewColumn.Name = "uxIDGrupaDjelatnikDataGridViewColumn";
			this.uxIDGrupaDjelatnikDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxIDGrupaDjelatnikDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxIDGrupaDjelatnikDataGridViewColumn.ReadOnly = false;		
			//
			// uxOrgJedDataGridViewColumn
			//
			this.uxOrgJedDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxOrgJedDataGridViewColumn.DataPropertyName = "OrgJed";
			this.uxOrgJedDataGridViewColumn.HeaderText = "OrgJed";
			this.uxOrgJedDataGridViewColumn.Name = "uxOrgJedDataGridViewColumn";
			this.uxOrgJedDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxOrgJedDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxOrgJedDataGridViewColumn.ReadOnly = false;		
			//
			// uxDozvolaZapisaDataGridViewColumn
			//
			this.uxDozvolaZapisaDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxDozvolaZapisaDataGridViewColumn.DataPropertyName = "DozvolaZapisa";
			this.uxDozvolaZapisaDataGridViewColumn.HeaderText = "DozvolaZapisa";
			this.uxDozvolaZapisaDataGridViewColumn.Name = "uxDozvolaZapisaDataGridViewColumn";
			this.uxDozvolaZapisaDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxDozvolaZapisaDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxDozvolaZapisaDataGridViewColumn.ReadOnly = false;		
			//
			// uxDozvolaPregledDataGridViewColumn
			//
			this.uxDozvolaPregledDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxDozvolaPregledDataGridViewColumn.DataPropertyName = "DozvolaPregled";
			this.uxDozvolaPregledDataGridViewColumn.HeaderText = "DozvolaPregled";
			this.uxDozvolaPregledDataGridViewColumn.Name = "uxDozvolaPregledDataGridViewColumn";
			this.uxDozvolaPregledDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxDozvolaPregledDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxDozvolaPregledDataGridViewColumn.ReadOnly = false;		
			//
			// uxIDDataGridViewColumn
			//
			this.uxIDDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxIDDataGridViewColumn.DataPropertyName = "ID";
			this.uxIDDataGridViewColumn.HeaderText = "ID";
			this.uxIDDataGridViewColumn.Name = "uxIDDataGridViewColumn";
			this.uxIDDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxIDDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxIDDataGridViewColumn.ReadOnly = true;		
			//
			// uxIDGrupaDjelatnikDataGridViewColumn
			//				
			this.uxIDGrupaDjelatnikDataGridViewColumn.DisplayMember = "Naziv";	
			this.uxIDGrupaDjelatnikDataGridViewColumn.ValueMember = "ID";	
			this.uxIDGrupaDjelatnikDataGridViewColumn.DisplayStyleForCurrentCellOnly = true;
			//uxIDGrupaDjelatnikDataGridViewColumn.DataSource = uxIDGrupaDjelatnikBindingSource;				
				
			
			// this
			this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
			this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
			this.Controls.Add(this.uxGrupaDozvoleDataGridView);
			this.Name = "GrupaDozvoleDataGridView";
			this.Size = new System.Drawing.Size(470, 300);
			//((System.ComponentModel.ISupportInitialize)(this.uxIDGrupaDjelatnikBindingSource)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.uxGrupaDozvoleErrorProvider)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.uxGrupaDozvoleDataGridView)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.uxGrupaDozvoleBindingSource)).EndInit();
			this.ResumeLayout(false);
		}
		#endregion
				
		#region events
		
		/// <summary>
		/// Raised the CurrentEntityChanged event.
		/// </summary>
		protected void OnCurrentEntityChanged()
		{
			if (CurrentEntityChanged != null)
			{
				GrupaDozvoleDataGridViewEventArgs args = new GrupaDozvoleDataGridViewEventArgs();
				args.GrupaDozvole = _currentGrupaDozvole;
				CurrentEntityChanged(this, args); 
			}
		}
		
		#endregion
		
		/// <summary>
		/// Strongly typed event 
		/// </summary>
		public class GrupaDozvoleDataGridViewEventArgs : System.EventArgs
		{
			private Entities.GrupaDozvole	_GrupaDozvole;
	
			/// <summary>
			/// the  Entities.GrupaDozvole instance.
			/// </summary>
			public Entities.GrupaDozvole GrupaDozvole
			{
				get { return _GrupaDozvole; }
				set { _GrupaDozvole = value; }
			}	
		}
		
		/// <summary>
		/// Handles the DataError event of the uxGrupaDozvoleDataGridView control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="T:System.Windows.Forms.DataGridViewDataErrorEventArgs"/> instance containing the event data.</param>
		protected void OnGrupaDozvoleDataGridViewDataError(object sender, System.Windows.Forms.DataGridViewDataErrorEventArgs e)
		{
			System.Diagnostics.Debug.WriteLine(string.Format( "{0}, {1}", e.ColumnIndex, e.RowIndex));
		}
		
		/// <summary>
		/// Handles the CellValueNeeded event of the uxGrupaDozvoleDataGridView control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="T:System.Windows.Forms.DataGridViewCellValueEventArgs"/> instance containing the event data.</param>
		protected void OnGrupaDozvoleDataGridViewCellValueNeeded(object sender, System.Windows.Forms.DataGridViewCellValueEventArgs e)
		{
			switch(uxGrupaDozvoleDataGridView.Columns[e.ColumnIndex].Name)
			{
					case "uxIDGrupaDjelatnikDataGridViewColumn":
						e.Value = GrupaDozvoleList[e.RowIndex].IDGrupaDjelatnik;
						break;
					case "uxOrgJedDataGridViewColumn":
						e.Value = GrupaDozvoleList[e.RowIndex].OrgJed;
						break;
					case "uxDozvolaZapisaDataGridViewColumn":
						e.Value = GrupaDozvoleList[e.RowIndex].DozvolaZapisa;
						break;
					case "uxDozvolaPregledDataGridViewColumn":
						e.Value = GrupaDozvoleList[e.RowIndex].DozvolaPregled;
						break;
					case "uxIDDataGridViewColumn":
						e.Value = GrupaDozvoleList[e.RowIndex].ID;
						break;
				default:
				break;
			}
		}
		
		/// <summary>
		/// Handles the CellValuePushed event of the uxGrupaDozvoleDataGridView control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="T:System.Windows.Forms.DataGridViewCellValueEventArgs"/> instance containing the event data.</param>
		protected void OnGrupaDozvoleDataGridViewCellValuePushed(object sender, System.Windows.Forms.DataGridViewCellValueEventArgs e)
		{
			switch(uxGrupaDozvoleDataGridView.Columns[e.ColumnIndex].Name)
			{
					case "uxIDGrupaDjelatnikDataGridViewColumn":
						GrupaDozvoleList[e.RowIndex].IDGrupaDjelatnik = (System.Int32)e.Value;
						break;
					case "uxOrgJedDataGridViewColumn":
						GrupaDozvoleList[e.RowIndex].OrgJed = (System.String)e.Value;
						break;
					case "uxDozvolaZapisaDataGridViewColumn":
						GrupaDozvoleList[e.RowIndex].DozvolaZapisa = (System.Int32)e.Value;
						break;
					case "uxDozvolaPregledDataGridViewColumn":
						GrupaDozvoleList[e.RowIndex].DozvolaPregled = (System.Int32)e.Value;
						break;
					case "uxIDDataGridViewColumn":
						GrupaDozvoleList[e.RowIndex].ID = (System.Int32)e.Value;
						break;
				default:
				break;
			}
		}
	}
}
